package lab4.io;

import config.ATMData;
import config.Config;

import java.io.*;
import java.net.Socket;
import java.net.UnknownHostException;

/**
 * Created by Student on 17.12.2014.
 */
public class ClientDelayIO {

    public static final int TESTS_NUMBER = 100;

    /**
     * Client send 2 commands to server.
     * First - 'get' - to get special object from server
     * Second - 'ok' - when client get this object
     * Server calculate time between the first command and the second
     *
     * @param args
     */
    public static void main(String[] args) {
        try (Socket s = new Socket(Config.ADDRESS, Config.PORT);
             ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream());
             ObjectInputStream ois = new ObjectInputStream(s.getInputStream());) {
            for (int i = 0; i < TESTS_NUMBER; i++) {
                oos.writeObject("get");
                oos.flush();
                System.out.println("Get: " + (ATMData) ois.readObject());
                oos.writeObject("ok");
                oos.flush();
            }
        } catch (UnknownHostException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
